﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AbstractFactory.Tests
{
    [TestClass]
    public class FactoryTests
    {
        [TestMethod]
        public void GenerateBrickMaze()
        {
            // Use configuration to select the brick factory here.
            IMazeFactory factory = new BrickMazeFactory();
            var maze = CreateMaze(factory);

            Assert.AreEqual(2, maze.Rooms.Count());
            Assert.AreEqual(typeof(BrickRoom), maze.Rooms[0].GetType());
            Assert.AreEqual(typeof(BrickWall), maze.Rooms[0].EastWall.GetType());
            Assert.AreEqual(typeof(BrickDoor), maze.Rooms[0].EastWall.Door.GetType());
        }

        [TestMethod]
        public void GenerateWoodMaze()
        {
            // Use configuration to select the wood factory here.
            IMazeFactory factory = new WoodenMazeFactory();
            var maze = CreateMaze(factory);

            Assert.AreEqual(2, maze.Rooms.Count());
            Assert.AreEqual(typeof(WoodenRoom), maze.Rooms[0].GetType());
            Assert.AreEqual(typeof(WoodenWall), maze.Rooms[0].EastWall.GetType());
            Assert.AreEqual(typeof(WoodenDoor), maze.Rooms[0].EastWall.Door.GetType());
        }

        public Maze CreateMaze(IMazeFactory factory)
        {
            var room1 = factory.GetRoom();
            var room2 = factory.GetRoom();

            room1.EastWall = factory.GetWall();
            room1.SouthWall = factory.GetWall();
            room1.WestWall = factory.GetWall();
            room1.NorthWall = factory.GetWall();

            room2.EastWall = factory.GetWall();
            room2.SouthWall = factory.GetWall();
            room2.WestWall = room1.EastWall;
            room2.NorthWall = factory.GetWall();

            room1.EastWall.Door = factory.GetDoor();

            var maze = new Maze();
            maze.Rooms.Add(room1);
            maze.Rooms.Add(room2);

            return maze;
        }
    }
}
